package com.justgame.project.service.art.query;

import java.util.List;
import java.util.ArrayList;
import java.util.Optional;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.justgame.project.cloud.common.query.Column;
import com.justgame.project.cloud.common.query.BaseSelectBuilder;
import com.justgame.project.cloud.common.query.AbstractQueryWrapper;
import com.justgame.project.cloud.common.query.Query;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.justgame.project.service.art.entity.ArtPageComment;
import com.justgame.project.service.system.query.SysUserInfoQuery;
import com.justgame.project.service.art.entity.ArtPageInfo;
import com.justgame.project.service.system.entity.SysUserInfo;
import com.justgame.project.service.art.query.ArtPageCommentQuery;
import com.justgame.project.service.art.query.ArtPageInfoQuery;
import com.justgame.project.service.art.entity.ArtPageComment;
import com.justgame.project.service.art.wrapper.ArtPageCommentWrapper;

public class ArtPageCommentQuery extends AbstractQueryWrapper<ArtPageComment, MPJLambdaWrapper<ArtPageComment>, ArtPageCommentWrapper> {

    private ArtPageCommentQuery() {
        super(new MPJLambdaWrapper<>(ArtPageComment.class,"art_page_comment"));
    }

    public static ArtPageCommentQuery builder(){
        return new ArtPageCommentQuery();
    }

    public static class Select{

        private final List<Query> queries;

        protected Select(){
            queries = new ArrayList<>();
        }

        protected Select(List<Query> queries) {
            this.queries = queries;
        }

        public Query[] getQueriesArray() {
            return queries.toArray(new Query[0]);
        }

        public static SelectBuilder builder(){
            return new SelectBuilder();
        }

        public Query[] build(){
            return queries.toArray(new Query[0]);
        }

        public static class SelectBuilder extends BaseSelectBuilder {
            public SelectBuilder ArtPageComment(){
                return ArtPageComment(Column.all());
            }

            public SelectBuilder ArtPageComment(Column column){
                return add(Query.builder(ArtPageComment.class)
                            .selectColumns(column)
                            .build());
            }

            public SelectBuilder createUser(){
                return createUser(Column.all());
            }

            public SelectBuilder createUser(Column column){
                return createUser(column, null);
            }

            public SelectBuilder createUser(Column column,SysUserInfoQuery.Select selectQuery){
                return createUser("createUserWrapper", column, null);
            }

            public SelectBuilder createUser(String mappingName,Column column,SysUserInfoQuery.Select selectQuery){
                return add(Query.builder(SysUserInfo.class)
                            .mapping(mappingName)
                            .leftOn((SFunction<SysUserInfo,?>)SysUserInfo::getId)
                            .rightOn((SFunction<ArtPageComment,?>)ArtPageComment::getCreateUser)
                            .selectColumns(column)
                            .join(Optional.ofNullable(selectQuery).map(SysUserInfoQuery.Select::getQueriesArray).orElse(null))
                            .build());
            }

            public SelectBuilder updateUser(){
                return updateUser(Column.all());
            }

            public SelectBuilder updateUser(Column column){
                return updateUser(column, null);
            }

            public SelectBuilder updateUser(Column column,SysUserInfoQuery.Select selectQuery){
                return updateUser("updateUserWrapper", column, null);
            }

            public SelectBuilder updateUser(String mappingName,Column column,SysUserInfoQuery.Select selectQuery){
                return add(Query.builder(SysUserInfo.class)
                            .mapping(mappingName)
                            .leftOn((SFunction<SysUserInfo,?>)SysUserInfo::getId)
                            .rightOn((SFunction<ArtPageComment,?>)ArtPageComment::getUpdateUser)
                            .selectColumns(column)
                            .join(Optional.ofNullable(selectQuery).map(SysUserInfoQuery.Select::getQueriesArray).orElse(null))
                            .build());
            }

            public SelectBuilder parentComment(){
                return parentComment(Column.all());
            }

            public SelectBuilder parentComment(Column column){
                return parentComment(column, null);
            }

            public SelectBuilder parentComment(Column column,ArtPageCommentQuery.Select selectQuery){
                return parentComment("parentCommentWrapper", column, null);
            }

            public SelectBuilder parentComment(String mappingName,Column column,ArtPageCommentQuery.Select selectQuery){
                return add(Query.builder(ArtPageComment.class)
                            .mapping(mappingName)
                            .leftOn((SFunction<ArtPageComment,?>)ArtPageComment::getId)
                            .rightOn((SFunction<ArtPageComment,?>)ArtPageComment::getParentId)
                            .selectColumns(column)
                            .join(Optional.ofNullable(selectQuery).map(ArtPageCommentQuery.Select::getQueriesArray).orElse(null))
                            .build());
            }

            public SelectBuilder artPageInfo(){
                return artPageInfo(Column.all());
            }

            public SelectBuilder artPageInfo(Column column){
                return artPageInfo(column, null);
            }

            public SelectBuilder artPageInfo(Column column,ArtPageInfoQuery.Select selectQuery){
                return artPageInfo("artPageInfoWrapper", column, null);
            }

            public SelectBuilder artPageInfo(String mappingName,Column column,ArtPageInfoQuery.Select selectQuery){
                return add(Query.builder(ArtPageInfo.class)
                            .mapping(mappingName)
                            .leftOn((SFunction<ArtPageInfo,?>)ArtPageInfo::getId)
                            .rightOn((SFunction<ArtPageComment,?>)ArtPageComment::getPageId)
                            .selectColumns(column)
                            .join(Optional.ofNullable(selectQuery).map(ArtPageInfoQuery.Select::getQueriesArray).orElse(null))
                            .build());
            }

            public Select build(){
                return new Select(getQueries());
            }
        }

    }
}